Skip to content

Conversation

@petergithub
Copy link

@petergithub petergithub commented Oct 27, 2025

DBHub supports connecting to multiple databases simultaneously:

Configuration

  • Single Database: Use DSN environment variable or --dsn command line argument
  • Multiple Databases: Use DSN_dev, DSN_test, etc. environment variables

Usage Examples

# Single database (backward compatible)
export DSN="postgres://user:pass@localhost:5432/mydb"

# Multiple databases
export DSN_dev="postgres://user:pass@localhost:5432/db1"
export DSN_test="mysql://user:pass@localhost:3306/db2"
export DSN_prod="sqlite:///path/to/database.db"

HTTP Transport Endpoints

When using HTTP transport (--transport=http), multiple endpoints are available:

  • http://localhost:8080/message - Default database (first configured)
  • http://localhost:8080/message/{databaseId} - Specific database (e.g., http://localhost:8080/message/dev)

STDIO Transport

  • STDIO transport uses the default database
  • Available databases are listed in startup messages
  • Use HTTP transport for full multi-database access

Database Context

All MCP tools, resources, and prompts support database-specific operations:

  • Tools: execute_sql_{databaseId}
  • Resources: Database-specific schema exploration
  • Prompts: generate_sql_{databaseId}, explain_db_{databaseId}

@petergithub petergithub requested a review from tianzhou as a code owner October 27, 2025 07:41
@petergithub
Copy link
Author

petergithub commented Oct 27, 2025

Implements feature from issue Does it support multiple database connections? and is it possible to connect to two different databases? with multiple http endpoint.

@petergithub petergithub changed the title Multi-Database Support Multi-Databases Support Oct 27, 2025
@tianzhou
Copy link
Contributor

Thanks for the PR, could you please share how you would like to use this feature from the MCP client side (e.g. Claude / Cursor / VSCode etc)?

I am thinking of supporting this scenairo in a more scalable way

@petergithub
Copy link
Author

Thanks for the question. Our project utilizes multiple databases, and we query these databases through the MCP server's HTTP endpoint using a workflow like Dify provide.

Current Scenario & Problem:
The current implementation of the dbhub component requires us to launch and maintain multiple separate dbhub services, one for each database we need to query. This leads to increased resource consumption due to the redundancy of deploying multiple instances of the service.

How We Intend to Use the Feature:
By adding support for multiple data sources within a single instance (as suggested by your PR), we would be able to:

  1. Launch only a single dbhub service.
  2. This single service would then be able to query multiple databases concurrently.

Benefit (Scalability & Efficiency):
This change significantly reduces the need to deploy and manage multiple dbhub services, thereby decreasing resource usage and streamlining our deployment process."

By the way, would you please to share your thoughts about the more scalable way?

@tianzhou
Copy link
Contributor

@petergithub I am considering provide a configuration file in the TOML format to allow user to configure multiple databases.

@petergithub
Copy link
Author

@petergithub I am considering provide a configuration file in the TOML format to allow user to configure multiple databases.

It is great with a configuration file in TOML format.
I'm using the .env file for configuration primarily to ensure compatibility with the current setup and avoid introducing new files.

If multiple endpoints are fine, I'll switch the config to TOML. Let me know the desired schema/format definition.

@petergithub
Copy link
Author

TOML format offers greater flexibility.
When I configured with a .env file, it is difficult to define the structures, and the parsing logic is significantly more complex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants